package gtkwire.widget;

import java.awt.Rectangle;
import gtkwire.*;
import gtkwire.widget.cairo.CairoGraphics;

/**   FIXME : create hässäkkä
*A canvas widget that can be drawn into using Cairo graphics library.
*/

public class GtkCairoDrawable extends GtkDrawableArea
{
//*Java platforms Shapes are reused here to describe shapes, but all the other features like setting paint,
//*stroke and transformation are different, and cairo specific.
//*See generic Cairo tutorials for further instructions.
//*/

	/**
	* cairo_id for next GtkCairoDrawable to be created. 
	*/
	private static int next_cairo_id = 0;
	/**
	* Cairo id for this widget.
	*/
	private int cairo_id = -1;
	/**
	* Number of cairo drawables user can create.
	*/
	private static int MAX_CAIRO_DRAWABLES = 100;
	/**
	* Flag for initialising native side
	*/
	private static boolean native_initialized = false;

	public GtkCairoDrawable()
	{
		super();
		this.widgetType = WT_GtkCairoDrawable;
		if( !native_initialized ) initNative();
		native_initialized = true;
		gtkCreate();
	}

	/*
	* DO NOT USE THIS CONSTRUCTOR. It only exists to make this class compile.
	* Calling this constructor WILL TERMINATE PROGRAM.	
	public GtkCairoDrawable(String name, GladeKey key )
	{
		super(name, key);
		System.exit( 1 );
	}
	*/

	/**
	*Creates a real GTK+ object instance. Also creates a data structure in c -side of this lib for later acces.
	*Unless this is called, the widget is just a handle. The handle can be used to control widgets created using Glade.
	*<p>
	*This is overridden in GtkCairoDrawable, because special initialisation is needed.
	*/
	public void gtkCreate()
	{
		cairo_id = next_cairo_id;
		if( cairo_id >= MAX_CAIRO_DRAWABLES )
		{
			cairo_id = -1;
			throw new Error( "Too many GtkCairoDrawables created." );
		}

		app().createGTKWidget( getWidgetType(), getName(), getCreateData() );
		initDrawable( name, cairo_id );
		next_cairo_id++;
	}

	/**
	* Queues a repaint for defined area of this widget. When repaint occurs exposureEvent() method
	* will be called, and graphics object for painting on this widget is provided.
	*/
	public void queueDrawArea( Rectangle rect )
	{

	}

	/**
	* Queues a repaint for full area of this widget. When repaint occurs exposureEvent() method
	* will be called, and graphics object for painting on this widget is provided.
	*/
	public void queueDrawFull()
	{

	}

	/**
	* This method is called by platform when this widget needs to be repainted. Widget has either been exposed by a window event or repaint has been 
	*requested by calling by queueDrawArea() or queueFullDraw() methods. Use methods of CairoGraphics object to paint on the widget area.
	*<p>
	*Do NOT try instantiate a CairoGraphics object, it only works correctly when created and provided by the platform.
	*/
	public void exposureEvent( CairoGraphics g ){}

	//----------------------------------------------------------- NATIVE METHODS.
	private native static void  initNative();
	private native void initDrawable( String name, int cairo_id );
	
}//end class
